package xhwl.insurance.ui;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.ArrayList;

import xhwl.android.common.util.SPUtil;
import xhwl.android.common.util.ToastUtil;
import xhwl.insurance.R;
import xhwl.insurance.BaseActivity;
import xhwl.insurance.http.api.FeedBackApi;
import xhwl.insurance.http.api.VideoListApi;
import xhwl.insurance.http.bean.resp.VideoListResp;
import xhwl.insurance.http.bean.resp2.HttpResp;
import xhwl.retrofitrx.HttpException;
import xhwl.retrofitrx.HttpManager;
import xhwl.retrofitrx.OnNextListener;

public class FeedBackActivity extends BaseActivity implements OnClickListener {

	Button feed_action;
	EditText feed_device;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.feed_back);
	}

	@Override
	public void initViews() {
		initTitleViews();
		feed_device = (EditText) findViewById(R.id.feed_device);
		feed_action = (Button) findViewById(R.id.feed_action);
	}

	@Override
	protected void setUpTitleView() {
		titleTextView.setText("意见反馈");
	}

	@Override
	public void initListener() {
		feed_action.setOnClickListener(this);
		backImageView.setOnClickListener(this);
	}

	@Override
	public void loadData() {

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_left_imageview:
			finish();
			break;
		case R.id.feed_action:
			if(feed_device.getText().toString().equals("")){
				Toast.makeText(this, "请输入您的意见", Toast.LENGTH_SHORT).show();
			}else{
				String opinion = feed_device.getText().toString().trim();
				getData(opinion);

			}
		default:
			break;
		}

	}

	public void getData(String opinion) {
		String member_id = SPUtil.getPersonInfoSp().getString(SPUtil.SPPersonInfo.MEMBER_ID, "");
		String client_type = "27";
		FeedBackApi api = new FeedBackApi(member_id, client_type, opinion);
		HttpManager.getInstance().dealHttp(this, api, new OnNextListener<HttpResp>() {
			@Override
			public void onNext(HttpResp resp) {
				if (resp.isOk()) {
					Toast.makeText(FeedBackActivity.this, "意见反馈提交成功", Toast.LENGTH_SHORT).show();
					finish();
				}else {
					Toast.makeText(FeedBackActivity.this, resp.message, Toast.LENGTH_SHORT).show();
				}
			}

			@Override
			public void onError(HttpException ex) {
				super.onError(ex);

			}
		});

	}
}
